﻿<Window x:Class="CodeAngel.UI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:CodeAngel.UI"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance Type=local:MainWindowViewModel}"
        Title="Code Angel v9" Height="446" Width="614" WindowStartupLocation="CenterScreen" 
        Icon="/CodeAngel.UI;component/Resources/Images/GenerateAll.ico">
    
    <Window.Resources>

        <Style x:Key="EnabledWhenDomainExistsButtonStyle" BasedOn="{StaticResource MenuButtonStyle}" TargetType="Button">
            <Setter Property="IsEnabled" Value="{Binding CurrentDomain, Converter={StaticResource NullToFalseConverter}}" />
        </Style>
        
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <!-- Toolbar -->
        <Border BorderBrush="Black" Background="Black" BorderThickness="1">
            <StackPanel Orientation="Horizontal">
                <Button Command="{Binding SaveCurrentDomainCommand}"  Style="{StaticResource EnabledWhenDomainExistsButtonStyle}" >
                    <Image Source="/CodeAngel.UI;component/Resources/Images/Save_24.png" Height="22" Width="22" />
                </Button>
                <Button Command="{Binding OpenDomainCommand}"  Style="{StaticResource MenuButtonStyle}" Margin="6,0,0,0" ToolTip="Open Domain" >
                    <Image Source="/CodeAngel.UI;component/Resources/Images/Open_24.png" />
                </Button>
                <Button Command="{Binding CreateNewDomainCommand}"  Style="{StaticResource MenuButtonStyle}" Margin="6,0,0,0" ToolTip="New Domain">
                    <Image Source="/CodeAngel.UI;component/Resources/Images/Domain_New_24.png" />
                </Button>
                <Button Command="{Binding GenerateDomainFilesCommand}" Style="{StaticResource EnabledWhenDomainExistsButtonStyle}" Margin="6,0,0,0" ToolTip="Generate" >
                    <Image Source="/CodeAngel.UI;component/Resources/Images/GenerateDomain.ico" Height="24" Width="24" />
                </Button>
                <Button Command="{Binding GenerateDomainFilesAndCloseCommand}" Style="{StaticResource EnabledWhenDomainExistsButtonStyle}" Margin="6,0,0,0" ToolTip="Generate and Close" >
                    <Image Source="/CodeAngel.UI;component/Resources/Images/GenerateAllAndExit.ico" Height="24" Width="24" />
                </Button>
                <!--<Button Command="{Binding AddSecurityEntityDefsCommand}" Margin="160,0,0,0" >
                    Add Security
                </Button>-->
            </StackPanel>
        </Border>


        <!-- Domain -->
        <Grid Grid.Row="1" Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <local:LabeledTextBox Label="Name" Text="{Binding CurrentDomain.Name}" />
                <local:LabeledTextBox Label="Namespace" Text="{Binding CurrentDomain.Namespace}" Grid.Column="2"/>
            </Grid>

            <!-- Data -->
            <TabControl Grid.Row="2" Margin="0,6,0,0" VerticalAlignment="Stretch">

                <!-- Entity Definitions -->
                <TabItem Header="Entity Definitions">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <!-- Toolbar -->
                        <Border BorderBrush="Black" BorderThickness="1">
                            <StackPanel Orientation="Horizontal">
                                <Button Content="New" Command="{Binding CreateNewEntityDefCommand}" />
                                <local:LabeledComboBox Label="Filter" ItemsSource="{Binding DistinctSubFolders}" HorizontalAlignment="Center" Margin="15,0,0,0" Height="26" Width="200" 
                                                       SelectedItem="{Binding FilterEntityDefsByThisSubFolder}"/>
                                <Button Content="X" Command="{Binding ClearFilterEntityDefsByThisSubFolderCommand}" Margin="2" />
                            </StackPanel>
                        </Border>

                        <!-- Data -->
                        <ItemsControl x:Name="EntityDefsListBox" ItemsSource="{Binding EntityDefsCollectionView}" Grid.Row="1" Margin="0,6,0,0">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <local:ListItemControl OpenCommand="{Binding ElementName=EntityDefsListBox, Path=DataContext.OpenEntityDefCommand}"
                                                           DeleteCommand="{Binding ElementName=EntityDefsListBox, Path=DataContext.DeleteEntityDefCommand}"
                                                           MarkedAsDeleted="{Binding FlaggedAsDeleted, Mode=TwoWay}">
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold"  VerticalAlignment="Center" Margin="3" />
                                    </local:ListItemControl>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                    </Grid>
                </TabItem>

                <!-- Databases -->
                <TabItem Header="Databases">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <GroupBox Header="Development">
                            <local:DatabaseControl DataContext="{Binding DevelopmentDatabaseViewModel}"/>
                        </GroupBox>

                        <GroupBox Header="Production" Grid.Column="2">
                            <local:DatabaseControl DataContext="{Binding ProductionDatabaseViewModel}" />
                        </GroupBox>

                    </Grid>
                </TabItem>

                <!-- Projects -->
                <TabItem Header="Projects">
                    <StackPanel>
                        <GroupBox Header="Domain Project">
                            <StackPanel>
                                <local:LabeledTextBox Label="Project Name" Text="{Binding CurrentDomain.ProjectName}" LabelWidth="76"/>
                                <local:LabeledTextBox Label="Relative Path" Text="{Binding CurrentDomain.ProjectRelativePath}" LabelWidth="76" />
                            </StackPanel>
                        </GroupBox>

                        <GroupBox Header="Services Project">
                            <StackPanel>
                                <local:LabeledTextBox Label="Project Name" Text="{Binding CurrentDomain.ServicesProjectName}" LabelWidth="76"/>
                                <local:LabeledTextBox Label="Relative Path" Text="{Binding CurrentDomain.ServicesProjectRelativePath}" LabelWidth="76"/>
                            </StackPanel>
                        </GroupBox>
                    </StackPanel>
                </TabItem>

            </TabControl>


        </Grid>

        <!-- Logging in -->
        <Border Background="#aa000000" Grid.RowSpan="2" Visibility="{Binding IsLoggingIn, Converter={StaticResource TrueToVisibleConverter}}">
            <TextBlock Text="{Binding LogInMessage}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
        </Border>

    </Grid>
</Window>
